#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-08-10 9:42 上午
# @Author  : yangdy
# @File    : 2020-08-08.2.5469.K次操作转变字符串
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def canConvertString(self, s: str, t: str, k: int) -> bool:
        ans = True
        ls = len(s)
        lt = len(t)
        if ls != lt:
            return False
        ops = [k//26+(1 if k % 26 >= x else 0) for x in range(26)]

        def distance(x, y):
            xn = ord(x) - ord('a')
            yn = ord(y) - ord('a')
            if xn <= yn:
                return yn - xn
            else:
                return yn - xn + 26

        for i in range(ls):
            di = distance(s[i], t[i])
            if di <= 0:
                continue
            if di > k:
                return False
            if ops[di] > 0:
                ops[di] -= 1
            else:
                return False

        return ans


questions = [
    ('input', 'ouput', 9),
    ('abc', 'bcd', 10),
    ('aab', 'bbb', 27),
]

work(questions, lambda q: Solution().canConvertString(q[0], q[1], q[2]))
